import tkinter as tk
from rocketmq.client import Producer, Message

# 配置 RocketMQ
NAMESRV_ADDR = "192.168.13.208:9876"  # 你的 RocketMQ NameServer 地址
TOPIC = "warn-registerRes "
PRODUCER_GROUP = "TestProducerGroup"


def send_message():
    producer = Producer(PRODUCER_GROUP)
    producer.set_namesrv_addr(NAMESRV_ADDR)
    producer.start()

    msg = Message(TOPIC)
    msg.set_body("{\"address\":\"192.168.3.43:7304\",\"code\":200,\"date\":1741318621165,\"id\":1,\"msg\":\"success\",\"name\":\"warn\",\"platform_type\":2,\"sk-token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJTS19BVVRIIiwiaWF0IjoxNzQxMzE4NjIxLCJleHAiOjE3NDE0MDUwMjF9.eQGN_7STYtcMEtZgW2IO4rmK-v_XFe6o9qvuOfjAB9A\"}")
    producer.send_sync(msg)

    producer.shutdown()
    print("消息已发送")


# 创建 GUI 界面
root = tk.Tk()
root.title("RocketMQ 发送器")

toggle_button = tk.Button(root, text="发送消息", command=send_message)
toggle_button.pack(pady=20)

root.mainloop()
